<template>
    <el-container class="jxc_setting_container">
        <el-main>
            <el-card class="box-card">
                <el-divider content-position="left" class="title">系统配置</el-divider>
                <SettingForm type="jxc_setting" :rules="jxcRules" :fields="jxcFields"
                             label-width="150px" @event="handleJxcEvent" />
            </el-card>
        </el-main>
    </el-container>
</template>

<script>
export default {
    name: "JxcSetting",
    components: {
        SettingForm: () => import("@common/views/common/SettingForm"),
    },
    data() {
        return {
            jxcRules: {
                default_gross_profit_rate: [
                    { required: true, message: "请输入最低毛利率，例如：0.10", trigger: "blur" },
                ],
                default_tax_ratio: [
                    { required: true, message: "请输入税率，例如：0.06", trigger: "blur" },
                ],
            },
            jxcFields: [
                {
                    label: '采购订单自动审核',
                    prop: 'auto_approval_buy_order',
                    type: 'radioGroupButton',
                    defaultValue: 0,
                    children: [
                        { value: 1, name: '开启' },
                        { value: 0, name: '关闭' },
                    ],
                },
                {
                    label: '采购退货单自动审核',
                    prop: 'auto_approval_buy_return',
                    type: 'radioGroupButton',
                    defaultValue: 0,
                    children: [
                        { value: 1, name: '开启' },
                        { value: 0, name: '关闭' },
                    ],
                },
                {
                    label: '销售订单自动审核',
                    prop: 'auto_approval_sale_order',
                    type: 'radioGroupButton',
                    defaultValue: 0,
                    children: [
                        { value: 1, name: '开启' },
                        { value: 0, name: '关闭' },
                    ],
                },
                {
                    label: '销售退货单自动审核',
                    prop: 'auto_approval_sale_return',
                    type: 'radioGroupButton',
                    defaultValue: 0,
                    children: [
                        { value: 1, name: '开启' },
                        { value: 0, name: '关闭' },
                    ],
                },
                {
                    label: '入库单自动审核',
                    prop: 'auto_approval_in_bill',
                    type: 'radioGroupButton',
                    defaultValue: 0,
                    children: [
                        { value: 1, name: '开启' },
                        { value: 0, name: '关闭' },
                    ],
                },
                {
                    label: '出库单自动审核',
                    prop: 'auto_approval_out_bill',
                    type: 'radioGroupButton',
                    defaultValue: 0,
                    children: [
                        { value: 1, name: '开启' },
                        { value: 0, name: '关闭' },
                    ],
                },
                {
                    label: '盘点单自动审核',
                    prop: 'auto_approval_stock_inventory',
                    type: 'radioGroupButton',
                    defaultValue: 0,
                    children: [
                        { value: 1, name: '开启' },
                        { value: 0, name: '关闭' },
                    ],
                },
                {
                    label: '开票申请自动审核',
                    prop: 'auto_approval_sale_invoice',
                    type: 'radioGroupButton',
                    defaultValue: 0,
                    children: [
                        { value: 1, name: '开启' },
                        { value: 0, name: '关闭' },
                    ],
                },
                {
                    label: '收票申请自动审核',
                    prop: 'auto_approval_buy_invoice',
                    type: 'radioGroupButton',
                    defaultValue: 0,
                    children: [
                        { value: 1, name: '开启' },
                        { value: 0, name: '关闭' },
                    ],
                },
                {
                    label: '采购订单只有一个供应商',
                    prop: 'buy_order_only_one_supplier',
                    type: 'radioGroupButton',
                    defaultValue: 0,
                    children: [
                        { value: 1, name: '开启' },
                        { value: 0, name: '关闭' },
                    ],
                },
                {
                    label: '销售订单审核控制毛利率',
                    prop: 'sale_order_audit_check_gross_profit_rate',
                    type: 'radioGroupButton',
                    defaultValue: 0,
                    children: [
                        { value: 1, name: '开启' },
                        { value: 0, name: '关闭' },
                    ],
                },
                {
                    label: '最低毛利率',
                    prop: 'default_gross_profit_rate',
                    type: 'input',
                    defaultValue: 0,
                    doubleInput: {
                        len: 4,
                        negative: false,
                    },
                    style: {
                        width: '200px',
                    },
                    filter(data) {
                        return data.sale_order_audit_check_gross_profit_rate === 1;
                    },
                },
                {
                    label: '税率',
                    prop: 'default_tax_ratio',
                    type: 'input',
                    defaultValue: 0,
                    doubleInput: {
                        len: 4,
                        negative: false,
                    },
                    style: {
                        width: '200px',
                    },
                },
                {
                    label: '单价小数位数',
                    prop: 'price_fraction',
                    type: 'radioGroupButton',
                    defaultValue: 2,
                    children: [
                        { value: 2, name: '2位' },
                        { value: 4, name: '4位' },
                    ],
                },
                {
                    label: '金额小数位数',
                    prop: 'amount_fraction',
                    type: 'radioGroupButton',
                    defaultValue: 2,
                    children: [
                        { value: 0, name: '0位' },
                        { value: 2, name: '2位' },
                        { value: 4, name: '4位' },
                    ],
                },
                {
                    label: '行业选择',
                    prop: 'industry_config',
                    type: 'radioGroupButton',
                    defaultValue: 'common',
                    children: [
                        { value: 'common', name: '普通' },
                        { value: 'clothing', name: '服装' },
                    ],
                },
                {
                    label: '服装尺寸预设',
                    prop: 'clothing_preset_size',
                    type: 'input',
                    defaultValue: 'XS,S,M,L,XL,2XL,3XL;28,29,30,31,32,33,34',
                    style: {
                        width: '400px',
                    },
                    filter(data) {
                        return data.industry_config === 'clothing';
                    },
                },
                {
                    label: '销售/采购对账单来源',
                    prop: 'reconciliation_source',
                    type: 'radioGroupButton',
                    defaultValue: 'order',
                    children: [
                        { value: 'order', name: '销售/采购订单' },
                        { value: 'stockBill', name: '出入库单' },
                    ],
                },
            ],
        };
    },
    methods: {
        handleGlobalEvent(event) {
            const _this = this;
            if (event.type === 'success') {
                _this.fetchDataNoCatch(_this.$api.API_ClearGlobalSettingCache).then(() => {
                    _this.storeDispatch('initGlobalSetting');
                });
            }
        },
        handleJxcEvent(event) {
            const _this = this;
            if (event.type === 'success') {
                _this.fetchDataNoCatch(_this.$api.API_ClearJxcSettingCache).then(() => {
                    _this.storeDispatch('jxc/initSetting');
                });
            }
        },
    },
}
</script>

<style lang="less" rel="stylesheet/less" scoped>
.jxc_setting_container {
    width: 100%;
    height: 100%;
    overflow: hidden;

    .title {

        .el-divider__text {
            font-size: 20px;
            font-weight: bold;
        }
    }
}
</style>
